package algorithm.search;

import java.util.Vector;

/**
 * @author bingo
 * @create 2018-02-28 9:29
 **/
public class Main {

    public static void main(String[] args) {

        // 使用spring作为我们的测试用例
        String filename = "demo/spring.txt";
        String  findWord ="god";
        Vector<String> words = new Vector<String>();
        if(FileOperations.readFile(filename, words)){
            System.out.println( "There are totally " + words.size() + " words in " + filename );
            // 测试 BinarySearchTree
            long startTime = System.currentTimeMillis();
            BinarySearchTree<String, Integer> bst = new BinarySearchTree<String, Integer>();
            System.out.println("单词总数："+words.size());
            for (String word: words) {
                Integer res = bst.search(word);
                if (res == null){
                    bst.insert(word, new Integer(1));
                }
                else{

                    bst.insert(word, res + 1);
                }

            }
           // bst.ahead(bst.getNode());

            // 输出spring中spring一词出现的频率
            if( bst.contain(findWord) ){
                System.out.println(findWord+":" + bst.search(findWord));
            }
            else {
                System.out.println("No word +"+findWord+" in " + filename);
            }
            long endTime = System.currentTimeMillis();
            System.out.println("BinarySearchTree , time: " + (endTime - startTime) + "ms.");
            System.out.println();

        }
    }
}
